<template>
  <div class="h-user-management clearfix">
   <Vmask :maskTitle='maskTitle' :maskData='maskData' :showMask='showMask' :maskWidth='maskWidth' @FnMask='FnMask'></Vmask>
   <div class="hsx-routre-title">
      <div class="routre-title-content">
        <span><i class="el-icon-discount mr10"></i>用户管理</span>><span>人员管理</span>
      </div>
    </div>
    <div class="hsx-role-management-menu w150 fl">
        <el-menu
          default-active="userManagement"
          class="el-menu-vertical-demo lh40"
          :router="true"
          >
          <el-menu-item index="userManagement">
            <i class="el-icon-d-arrow-right hsx-icon "></i>
            <span slot="title">人员管理</span>
          </el-menu-item>
        </el-menu>
      </div>
    <div class="user-management-right bgc">
      <h3>人员管理</h3>
      <div class="user-management-content bgc-fff">
      <div class="row row-btn tc default-color lh40">
        <span @click="FnOperation({type:'add'})">新增</span>
        <span @click="FnOperation({type:'edit'})">编辑</span>
        <span @click="FnOperation({type:'delete'})">删除</span>
        <span @click="FnOperation({type:'prohibit'})">禁用</span>
        <span @click="FnOperation({type:'enable'})">启用</span>
      </div>
      <div class="search">
        <div class="row lh40 clearfix mb10 mb15">
          <div class="row-item clearfix fl mr15">
            <span class="row-item-title fl">
              部门名称：
            </span>
            <span class="fl span-input">
              <el-input placeholder="请输入内容" v-model.trim="regionName"></el-input>
            </span>
        </div>
        <div class="row-item clearfix fl mr15">
            <span class="row-item-title fl">
              姓名：
            </span>
            <span class="fl span-input">
              <el-input placeholder="请输入内容" v-model.trim="realName"></el-input>
            </span>
        </div>
        <div class="row-item clearfix fl mr15">
            <span class="row-item-title fl">
              账号：
            </span>
            <span class="fl span-input">
              <el-input placeholder="请输入内容" v-model.trim="userName"></el-input>
            </span>
        </div>
        <div class="row-item clearfix fl mr15">
            <span class="row-item-title fl">
              手机号码：
            </span>
            <span class="fl span-input">
              <el-input placeholder="请输入内容" v-model.trim="mobile"></el-input>
            </span>
        </div>
        </div>
        <div class="row mb15">
          <el-row>
            <el-button type="primary" @click="FnSearch">搜索</el-button>
            <el-button @click="FnEmpty">清空</el-button>
          </el-row>
        </div>
      </div>
      <div class="show-table">
        <ShowTable :tableData='tableData' :selections='selections' :lableList='lableList' :talLength='talLength' :pageSize='pageSize' :pageNum='pageNum' @getSortableFn='getSortableFn'></ShowTable>
      </div>
    </div>
    </div>
    
  </div>
</template>

<script>
import ShowTable from "../components/table/show-table"
import Vmask from "../components/v-mask/v-mask"
import {ManagerUserAllList,EditInstitution,ManagerUserList,Code,ManagerUserStop,DeleteManagerUser,GetAllOrganizations,WorkJobList,GetRoleList,AddManagerUser,EditManagerUser} from '@/axios/api.js'
export default {
  name: '',
  data(){
    return {
      regionNameList:[],
      topRegionNameList:[
        // {
        //   id: 'zhinan',
        //   label: '指南',
        //   children: [{
        //     id: 'shejiyuanze',
        //     label: '设计原则',
        //     children: [{
        //       id: 'yizhi',
        //       label: '一致'
        //     }]
        //   }, {
        //     id: 'daohang',
        //     label: '导航',
        //     children: [{
        //       id: 'cexiangdaohang',
        //       label: '侧向导航'
        //     }]
        //   }]
        // }, 
        ],//所属的行政管理区
      maskWidth:'400px',
      maskTitle:'',
      maskData:{},
      showMask:false,
      regionName:'',
      realName:'',
      userName:'',
      mobile:'',
      pageSize:15,
      pageNum:1,
      tableData:[
        // {
        // id:'ID',
        // n1:'姓名',
        // n2:'账号',
        // n3:'手机号码',
        // n4:'角色',
        // n5:'岗位',
        // n6:'所属行政区',
        // n7:'所属部门',
        // n8:'是否禁用',
        // }
      ],
      selections:false,
      talLength:0,
      lableList:{
        id:'ID',
        n1:'姓名',
        n2:'账号',
        n3:'手机号码',
        n4:'角色',
        n5:'岗位',
        n6:'所属行政区',
        n7:'所属部门',
        n8:'是否禁用',
      },
      laseData:{},
      selectionId:'',//单击行点中的id
      defaultData:{//新增 编辑 是否的默认数据
        isStopList:[{label:'是',value:1},{label:'否',value:0}],
        enableWorkList:[{label:'是',value:1},{label:'否',value:0}],//排班 enableWork
        isTransferList:[{label:'是',value:1},{label:'否',value:0}],//是否默认转派员：
        isAcceptList:[{label:'是',value:1},{label:'否',value:0}],//是否默认承办员：
        isAcceptManagerList:[{label:'是',value:1},{label:'否',value:0}],//是否默认承办员主管：
        isSupportList:[{label:'是',value:1},{label:'否',value:0}],//是否在线：
        isCallList:[{label:'是',value:1},{label:'否',value:0}],//是否话务：
      },
      workJobIdList:[],
      maskPageNum:1,
    }
  },
  props:[],
  created(){
    this.FnWorkJobList();//岗位列表
    this.FnGetAllOrganizations()//行政所属
    this.FnSearch()//人员管理列表
    // this.FnGetRoleList();//获取角色列表
  },
  mounted(){

  },
  methods:{
    FnReturnRegionName (list,id,arr) {//返回部门
      var that = this;
      var nList = list.slice();
      // console.log(id,'id')
      var newArr = arr.slice();
      for(var i=0;i<nList.length;i++) {
        if(nList[i].value==id) {
          newArr.push(nList[i].value) 
          // return newArr
        }else if(nList[i].children&&nList[i].children.length) {
          newArr.push(nList[i].value) 
          that.FnReturnRegionName(nList[i].children,id,newArr)
        }
      }
      return newArr
      // nList.forEach(function(v){
      //   if(v.value==id) {
      //     newArr.push(v.value) 
      //     return newArr
      //   }else if(v.children&&v.children.length) {
      //     newArr.push(v.value) 
      //     that.FnReturnRegionName(v.children,id,newArr)
      //   }
      // })
      
    },
    FnEditManagerUser(e) {//编辑前获取数据
      EditManagerUser({
        userId:e
      }).then(res=>{
        // console.log(res,'编辑前获取数据')
        var {obj} = res
        this.maskWidth='600px',
        this.maskTitle = '编辑人员';
        this.showMask = true;
        var roles=[];
        var eRoleName = res.obj.roles?(res.obj.roles.slice()):[];
        eRoleName.forEach((v)=>{
          roles.push({roleName:v.roleName,roleId:v.roleId})
        })
        this.FnReturnText(this.regionNameList,obj.regionId,'showRegionNameText');
        this.FnReturnText(this.regionNameList,obj.topRegionId,'showTopRegionNameText');
        this.maskData = {
          defaultBox:true,
          userId:obj.userId,//用户id
          personnelManagementBox:true,//人员管理弹框
          editStaff:true,//编辑人员
          realName:obj.realName,//姓名
          mobile:obj.mobile,//电话
          password:obj.password,
          userName:obj.userName,//账号名称	
          workJobId:obj.workJobId,//岗位
          workJobIdList:this.workJobIdList,
          roles,//选中的id数组
          roleNameList:[],
          topRegionName:[],//所属行政区
          showTopRegionNameText:this.showTopRegionNameText,//所属行政区--展示
          topRegionNameList:this.topRegionNameList,
          regionName:'',//部门
          showRegionNameText:this.showRegionNameText,//返回部门,//部门文本展示 
          regionNameList:this.regionNameList,////所属行政区一样
          isCall:obj.isCall,//是否话务员：
          isCallList:this.defaultData.isCallList,//是否话务员：
          extNumber:obj.extNumber,//绑定分机
          extPass:obj.extPass,//分机密码
          isStop:obj.isStop,
          isStopList:this.defaultData.isStopList,
          enableWork:obj.enableWork,
          enableWorkList:this.defaultData.enableWorkList,
          isTransfer:obj.isTransfer,//
          isTransferList:this.defaultData.isTransferList,//是否默认转派员：
          isAcceptManager:obj.isAcceptManager,//
          isAcceptManagerList:this.defaultData.isAcceptManagerList,//是否默认承办员：
          isAccept:obj.isAccept,
          isAcceptList:this.defaultData.isAcceptList,//是否默认承办员：
          isSupport:obj.isSupport,
          isSupportList:this.defaultData.isSupportList,//是否在线客服：
          tableData:this.FnGetRoleList(),
        }
      })
    },
    FnReturnText(l,id,text) {//根据传入的id，来显示匹配的文本
      var list = l.slice();
      var arr = []
      var that = this;
      if(!list.length) {
        return {}
      }
      for(var i=0;i<list.length;i++) {
        if(list[i].regionId==id) {
          var label = list[i].regionName;
          that[text] = {
            label,
            value:list[i].regionId
          }
          return
        }else if(list[i].children&&list[i].children.length>0) {
          for(var j=0;j<list[i].children.length;j++) {
             arr.push((list[i].children)[j])
          }
          if(i==(list.length-1)) {
            that.FnReturnText(arr,id,text)
          }
        }
      } 
    },
    FnGetRoleList () {//获取角色列表
      GetRoleList({
        pageIndex:this.maskPageNum,
        pageSize:5,
      }).then(res=>{
        if(res.code==Code) {
          // console.log(res,'获取角色列表')
          this.maskData.total = res.obj.total;
          var list = res.obj.records.slice();
          this.maskData.tableData = [];
          for(var i=0;i<list.length;i++) {
            this.maskData.tableData.push({
              id: list[i].roleId,
              name: list[i].roleName,
            })
          }
        }
      })
    },
    FnWorkJobList () {//岗位列表
      WorkJobList().then(res=>{
        if(res.code==Code) {
          this.workJobIdList = [];
          var list = res.obj.slice();
          for(var i=0;i<list.length;i++) {
            this.workJobIdList.push({
              value:list[i].workJobId,
              label:list[i].workJobName
            })
          }
        }
      })
    },
    FnDeleteManagerUser(userId) {
      DeleteManagerUser({
        userId,
        _method:'delete'
      }).then(res=>{
        if(res.code==Code) {
          this.$message.success("删除成功");
          this.FnSearch()
        }
        this.showMask = false;
      })
    },
    FnPaging() {//ManagerUserAllList  ManagerUserList
      ManagerUserList({
        regionName:this.laseData.regionName,
        realName:this.laseData.realName,
        userName:this.laseData.userName,
        mobile:this.laseData.mobile,
        pageIndex:this.pageNum,
        pageSize:this.pageSize,
      }).then(res=>{
        if(res.code==Code) {
          this.tableData = [];
          this.talLength = res.obj.total;
          var list = res.obj.records.slice();
          for(var i=0;i<list.length;i++) {
            this.tableData.push({
              id:list[i].userId,//'ID',
              n1:list[i].realName,//'姓名',
              n2:list[i].userName,//'账号',
              n3:list[i].mobile,//'手机号码',
              n4:list[i].roleNames,//'角色',
              n5:list[i].workJobName,//'岗位',
              n6:list[i].topRegionName,//'所属行政区',
              n7:list[i].regionName,//'所属部门',
              n8:list[i].isStop?'是':'否',//'是否禁用',
              row:list[i]
            })
          }
        }
      })
    },
    FnManagerUserList() {//人员管理列表
      ManagerUserList({
        regionName:this.laseData.regionName,
        realName:this.laseData.realName,
        userName:this.laseData.userName,
        mobile:this.laseData.mobile,
        pageIndex:this.pageNum,
        pageSize:this.pageSize,
      }).then(res=>{
        if(res.code==Code) {
          this.tableData = [];
          this.talLength = res.obj.total;
          var list = res.obj.records.slice();
          for(var i=0;i<list.length;i++) {
            this.tableData.push({
              id:list[i].userId,//'ID',
              n1:list[i].realName,//'姓名',
              n2:list[i].userName,//'账号',
              n3:list[i].mobile,//'手机号码',
              n4:list[i].roleNames,//'角色',
              n5:list[i].workJobName,//'岗位',
              n6:list[i].topRegionName,//'所属行政区',
              n7:list[i].regionName,//'所属部门',
              n8:list[i].sStop?'是':'否',//'是否禁用',
              row:list[i]
            })
          }
        }
      })
    },
    FnManagerUserStop (userId,stopFlag) {//禁用1，启用0
      ManagerUserStop({
        userId:userId,
        stopFlag:stopFlag,
      }).then(res=>{
        // console.log(res)
        if(res.code==Code) {
          if(stopFlag==1) {
            this.$message.success("禁用成功")
          }else {
            this.$message.success("启用成功")
          }
          this.FnSearch()
          this.showMask = false;
          this.maskData = {}
          this.maskTitle = ''
        }
      })
    },
    FnAddManagerUser(e) {//添加人员 新增人员
      var topRegionId = ''
      var regionId = ''
      var roles = [];//角色
      var rolesList = e.roles.slice();
      rolesList.forEach((v)=>{
        roles.push(v.roleId)
      })
      if(e.mobile===''||e.realName===''||e.password===''||e.userName===''||e.workJobId===''||e.isCall===''||e.extPass===''||e.isTransfer===''||e.isAccept===''||e.isSupport===''||e.isAcceptManager===''||e.isStop===''||e.extNumber===''||e.enableWork==='') {//
        this.$message.error("参数不能为空")
        return
      }
      if(!roles.length) {
        this.$message.error("角色不能为空")
        return
      }
      if(e.topRegionName&&e.topRegionName.length) {
        var topRegionNameLength = e.topRegionName.length
        topRegionId = e.topRegionName[topRegionNameLength-1]
      }else {
        this.$message.error("行政区域不能为空")
        return
      }
      if(e.regionName&&e.regionName.length) {
        var regionNameLength = e.regionName.length
        regionId = e.regionName[regionNameLength-1]
      }else {
        this.$message.error("部门不能为空")
        return
      }
      // console.log(e,'新增参数');
      AddManagerUser({
        mobile:e.mobile,//电话
        workJobId:e.workJobId,//岗位
        userName:e.userName,//账号名称	
        password:this.$md5(e.password),//密码	
        regionId,//部门	
        topRegionId,//行政
        realName:e.realName,//姓名	
        roles:JSON.stringify(roles),//角色id	
        isCall:e.isCall,//是否为话务员		
        enableWork:e.enableWork,//是否加入排班(0:否 1:是)		
        isAccept:e.isAccept,//是否是承办员		
        isAcceptManager:e.isAcceptManager,//是否是承办主管			
        isSupport:e.isSupport,//是否是客服人员				
        isStop:e.isStop,//用户停用标志，1：停用；0：未停用 默认为未停用				
        extNumber:e.extNumber,//分机号码			
        extPass:e.extPass,//分机密码			
        isTransfer:e.isTransfer,//默认转派
      }).then(res=>{
        // console.log("添加返回结果")
        if(res.code==Code) {
          this.showMask = false;
          this.maskData = {};
          this.$message.success("新增成功")
          this.FnSearch()//人员管理列表
        }
      })
    },
    FnModifyManagerUser(e) {//编辑人员--确定修改
      var roles = [];//角色
      var regionId = '';//部门
      var topRegionId = '';//所属行政区
      var rolesList = e.roles.slice();
      // console.log(e,'/编辑人员--确定修改')
      rolesList.forEach((v)=>{
        roles.push(v.roleId)
      })
      if(e.mobile===''||e.realName===''||e.password===''||e.userName===''||e.workJobId===''||e.isCall===''||e.extPass===''||e.isTransfer===''||e.isAccept===''||e.isSupport===''||e.isAcceptManager===''||e.isStop===''||e.extNumber===''||e.enableWork==='') {//
        this.$message.error("参数不能为空")
        return
      }
      if(e.showRegionNameText&&e.showRegionNameText.value) {//部门
        regionId = e.showRegionNameText.value
      }else if(e.regionName&&e.regionName.length) {
        var regionNameLength = e.regionName.length
        regionId = e.regionName[regionNameLength-1]
      }else {
        // console.log(regionId,'regionId')
        this.$message.error("部门不能为空")
        return
      }
      if(e.showTopRegionNameText&&e.showTopRegionNameText.value) {//所属行政区
        topRegionId = e.showTopRegionNameText.value
      }else if(e.topRegionName&&e.topRegionName.length) {
        var topRegionNameLength = e.topRegionName.length
        topRegionId = e.topRegionName[topRegionNameLength-1]
      }else {
        this.$message.error("所属行政区不能为空")
      }
      EditInstitution({
        userId:e.userId,//用户id	
        _method:'patch',
        mobile:e.mobile,
        realName:e.realName,//姓名
        password:this.$md5(e.password),//密码
        userName:e.userName,//账号
        workJobId:e.workJobId,//岗位
        regionId,//部门
        topRegionId,//所属行政区
        isCall:e.isCall,//是否话务员
        isStop:e.isStop,//是否禁用：
        // isStop:e.isStop,//是否禁用：
        extNumber:e.extNumber,//绑定分机
        enableWork:e.enableWork,//加入排班：
        extPass:e.extPass,//分机密码：
        isTransfer:e.isTransfer,//是否默认转派员：
        isAccept:e.isAccept,//是否默认承办员：
        isAcceptManager:e.isAcceptManager,//是否是承办主管	
        isSupport:e.isSupport,//是否在线客服：	
        roles:JSON.stringify(roles),//角色
      }).then(res=>{
        if(res.code==Code) {
          this.$message.success("修改成功");
          this.showMask = false;
          this.maskData = {};
          this.FnSearch()
          // console.log(res)
        }
      })
    },
    FnMask (e) {//弹框事件
      // console.log(e,'弹框事件')
      if(e.type=='true') {//确定
        if(e.content.isStops==true) {//禁用
          this.FnManagerUserStop(this.selectionId,1)
        }else if(e.content.enable==true) {//启用
          this.FnManagerUserStop(this.selectionId,0)
        }else if(e.content.delete==true) {//删除
          this.maskWidth = '400px'
          this.FnDeleteManagerUser(this.selectionId)
        }else if(e.content.addStaff==true) {//人员管理弹框--新增
          // if(e.content.mobile==''||e.content.realName==''||e.content.password==''||e.content.userName==''||e.content.workJobId==''||e.content.roleId==''||e.content.isCall==''||e.content.isStop==''||e.content.extNumber==''||e.content.enableWork==''||e.content.extPass==''||e.content.isTransfer==''||e.content.isAccept==''||e.content.isAcceptManager==''||e.content.isSupport==''){
          //   this.$message.error("参数不能为空")
          // }//||e.content.topRegionName.length==0||e.content.regionName.length==0
          //   console.log(e.content.mobile,'mobile')
          //   console.log(e.content.realName,'realName')
          //   console.log(e.content.password,'password')
          //   console.log(e.content.userName,'userName')
          //   console.log(e.content.workJobId,'workJobId')
          //   console.log(e.content.roleId,'roleId')
          //   console.log(e.content.topRegionName.length,'length')
          //   console.log(e.content.regionName.length,'length')
          //   console.log(e.content.isCall,'isCall')
          //   console.log(e.content.isStop,'isStop')
          //   console.log(e.content.extNumber,'extNumber')
          //   console.log(e.content.enableWork,'enableWork')
          //   console.log(e.content.extPass,'extPass')
          //   console.log(e.content.isTransfer,'isTransfer')
          //   console.log(e.content.isAccept,'isAccept')
          //   console.log(e.content.isAcceptManager,'isAcceptManager')
          //   console.log(e.content.isSupport,'isSupport')
          this.FnAddManagerUser(e.content)
        }else if(e.content.editStaff==true) {//人员管理弹框--编辑人员
          this.FnModifyManagerUser(e.content)
        }
        
      }else if (e.type=='false'){
        this.maskWidth='600px',
        this.showMask = false;
        this.maskData = {}
        this.maskTitle = '';
      }else if(e.type=='pageNum') {//页数改变
        this.maskPageNum = e.content;
        this.FnGetRoleList()
      }else if(e.type=='clickRow') {//单击行
        var isHave = true;
        for(var i=0;i<this.maskData.roles.length;i++) {
          if(e.content.id==this.maskData.roles[i].roleId) {
            isHave = false
            this.maskData.roles.splice(i,1)
          }
        }
        if(isHave) {
          this.maskData.roles.push({roleId:e.content.id,roleName:e.content.name})//选中的角色id
          // this.maskData.roleName.push(e.content.name)//选中的角色名字
        }
        
        // this.maskData.roleName = e.content.name
        // this.maskData.roleId = e.content.id;//选中的角色id
      }
    },
    FnOperation (e) {//操作
      this.maskData = {}
      if(e.type=='add'){//新增
        this.maskWidth='600px',
        this.maskTitle = '新增人员';
        this.showMask = true;
        this.maskPageNum = 1;
        this.maskData = {
          showRegionNameText:{},
          showTopRegionNameText:{},
          realName:'',//姓名
          mobile:'',//电话
          password:'',
          userName:'',//账号名称	
          workJobId:'',//岗位
          workJobIdList:this.workJobIdList,
          roleName:[],//角色名称--显示
          roles:[],//选中的id数组
          roleNameList:[],
          topRegionName:[],//所属行政区
          topRegionNameList:this.topRegionNameList,
          regionName:[],
          regionNameList:this.regionNameList,////所属行政区一样
          isCall:'',//是否话务员：
          isCallList:this.defaultData.isCallList,//是否话务员：
          extNumber:'',//绑定分机
          extPass:'',//分机密码
          isStop:'',
          isStopList:this.defaultData.isStopList,
          enableWork:'',
          enableWorkList:this.defaultData.enableWorkList,
          isTransfer:'',//
          isTransferList:this.defaultData.isTransferList,//是否默认转派员：
          isAcceptManager:'',//
          isAcceptManagerList:this.defaultData.isAcceptManagerList,//是否默认承办员：
          isAccept:'',
          isAcceptList:this.defaultData.isAcceptList,//是否默认承办员：
          isSupport:'',
          isSupportList:this.defaultData.isSupportList,//是否在线客服：
          tableData:this.FnGetRoleList(),
          defaultBox:true,
          personnelManagementBox:true,//人员管理弹框
          addStaff:true,//新增人员
        }
      }else if(e.type=='edit'){//编辑
        if(!this.selectionId) {
          this.$message.error("请先选中一行进行操作");
          return;
        }
        this.FnEditManagerUser(this.selectionId)//编辑前获取数据
        
      }else if(e.type=='delete'){//删除
        if(!this.selectionId) {
          this.$message.error("请先选中一行进行操作");
          return;
        }
        this.maskTitle = "删除提示";
        this.showMask = true;
        this.maskData = {
          defaultTitle:'请问是否删除',
          defaultTitleBox:true,
          trueOrFalse:true,
          delete:true
        }
      }else if(e.type=='prohibit'){//禁用
        if(!this.selectionId) {
          this.$message.error("请先选中一行进行操作");
          return;
        }
        this.maskTitle = "禁用提示";
        this.showMask = true;
        this.maskData = {
          defaultTitle:'请问是否禁用',
          defaultTitleBox:true,
          trueOrFalse:true,
          isStops:true
        }
      }else if(e.type=='enable'){//启用
        if(!this.selectionId) {
          this.$message.error("请先选中一行进行操作");
          return;
        }
        this.maskTitle = "启用提示";
        this.showMask = true;
        this.maskData = {
          defaultTitle:'请问是否启用',
          defaultTitleBox:true,
          trueOrFalse:true,
          enable:true
        }

      }
    },
    getSortableFn (e) {
      console.log(e,'表')
      if(e.type=='pageSize') {
        this.pageSize = e.content;
        this.FnPaging()
      }else if (e.type=='pageNum') {
        this.pageNum = e.content;
        this.FnPaging()
      }else if(e.type=="selectionRow") {
        this.selectionId = e.content.row.userId
      }
    },
    FnEmpty() {//清空按你
      this.regionName = this.realName = this.userName = this.mobile = '';
    },
    FnSearch() {//搜索
      this.pageNum = 1;
      this.pageSize = 15
      this.laseData = {
        regionName:this.regionName,
        realName:this.realName,
        userName:this.userName,
        mobile:this.mobile,
      }
      this.FnPaging()
    },
    FnGetAllOrganizations() {
      //所属行政管理 列表
      GetAllOrganizations({}).then(res => {
        if (res.code == Code) {
          //获取组织架构 部门编号列表
      GetAllOrganizations({}).then(res => {
        if (res.code == Code) {
          // console.log(res,'获取组织架构 部门编号列表')
          var list = [];
          list[0] = {
              pregionId: res.obj.pregionId,
              regionName: res.obj.regionName,
              regionCode: res.obj.regionCode,
              regionId: res.obj.regionId,
              children: res.obj.children?res.obj.children.slice():[]
          }
        this.allOrganizationsData = list.slice()
        this.regionNameList = list.slice()
        this.topRegionNameList = list.slice()
        }
      });
        return
          this.topRegionNameList = [];//所属行政管理
          this.regionNameList = [];//部门
          // var newAllOrganizationsData = [];
          // topRegionNameList = [
            // {
            //     value: 'zhinan',
            //     label: '指南',
            //     children: [{
            //       id: 'shejiyuanze',
            //       label: '设计原则',
            //       children: [{
            //         value: 'yizhi',
            //         label: '一致'
            //       }]
            //     }, {
            //       value: 'daohang',
            //       label: '导航',
            //       children: [{
            //         value: 'cexiangdaohang',
            //         label: '侧向导航'
            //       }]
            //     }]
            //   }
          // ];
          var list = res.obj.children.slice();
          this.topRegionNameList = [
            {
              value: res.obj.regionId,
              label: res.obj.regionName,
              children: []
            }
          ];
          this.regionNameList = [
            {
              value: res.obj.regionId,
              label: res.obj.regionName,
              children: []
            }
          ]
          for (var i = 0; i < list.length; i++) {
            var obj = {
              value: list[i].regionId,
              label: list[i].regionName,
              children: []
            };
            if (list[i].children && list[i].children.length != 0) {
              var secondaryList = list[i].children.slice();
              for (var j = 0; j < secondaryList.length; j++) {
                var o = {
                  value: secondaryList[j].regionId,
                  label: secondaryList[j].regionName,
                  children: []
                };
                obj.children.push(o)
              }
            }
            this.topRegionNameList[0].children.push(obj);
            this.regionNameList[0].children.push(obj);
          }
          // this.allOrganizationsData = newAllOrganizationsData
        }
      });
    },
  },
  components:{
    ShowTable,
    Vmask
  },
  computed:{

  },
  watch:{

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='scss' scoped>
.h-user-management {
  h3 {
    margin-bottom: 15px;
  }
  .user-management-right {
    min-width: 830px;
    padding: 15px;
    overflow: auto;

    .user-management-content {
      padding: 15px;
      .row-btn {
        display: flex;
        width: 300px;
        span {
          flex:1;
          cursor: pointer;
        }
      }
    }
    .show-table {
      margin-top: 15px;
    }
  }
}
</style>
